<template>
	<view class="tab-bar">
		<view class="tab-bar-border"></view>
		<view v-for="(item, index) in list" :key="index" class="tab-bar-item" @click="switchTab(item, index)">
			<van-icon :class="[selectedIndex === index ? 'tab-bar-item-van--icon-selected' : 'tab-bar-item-van--icon-not-selected']" :name="selectedIndex === index ? item.iconName : item.selectedIconName" />
			<view class="tab-bar-main-title" :style="{ color: selectedIndex === index ? selectedColor : color }">{{item.text}}</view>
		</view>
	</view>
</template>

<script>
	import { mapState, mapMutations } from 'vuex';
	
	export default {
		name: "CustomTabBar",
		data() {
			return {
				
			};
		},
		computed: {
			...mapState(['selectedIndex', 'color', 'selectedColor', 'list'])
			// ...mapState({
			// 	selectedIndex: state => state.selectedIndex,
			//  list: state => state.list
			// })
		},
		methods: {
			...mapMutations(['changeSelected']),
			switchTab(item, index) {
				this.changeSelected(index) //更新选中tab
			}
		}
	}
</script>

<style scoped>
	.tab-bar {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		height: 100rpx;
		background: white;
		display: flex;
		padding-bottom: env(safe-area-inset-bottom);
		box-shadow: 0rpx 0rpx 12rpx 1rpx rgba(0, 0, 0, 0.1);
	}
	.tab-bar-item {
		flex: 1;
		text-align: center;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
	}
	.tab-bar-item >>> van-icon {
		font-size: 55rpx;
	}
	.tab-bar-item-van--icon-not-selected {
		color: black;
	}
	.tab-bar-item-van--icon-selected {
		color: green;
	}
	.tab-bar-item >>> .tab-bar-main-title {
		font-size: 25rpx;
	}
</style>